package org.elzat.healthboxgatewayapp;

import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.elzat.healthboxgatewayapp.config.HealthBoxJwtConfig;
import org.elzat.healthboxgatewayapp.config.HealthBoxGatewayConfig;
import org.elzat.healthboxgatewayapp.config.HealthBoxSecurityConfig;
import org.elzat.healthboxgatewayapp.credentials.HealthBoxUserRole;
import org.elzat.healthboxgatewayapp.dto.HealthBoxUserVO;
import org.elzat.healthboxgatewayapp.service.HealthBoxUserModifyService;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;

@SpringBootApplication
@AllArgsConstructor
@Slf4j
@EnableDiscoveryClient
@EnableConfigurationProperties(value = {
        HealthBoxSecurityConfig.class,
        HealthBoxGatewayConfig.class,
        HealthBoxJwtConfig.class
})
public class HealthBoxGatewayAppApplication implements CommandLineRunner {
    public static void main(String[] args) {
        SpringApplication.run(HealthBoxGatewayAppApplication.class, args);
    }

    private final HealthBoxGatewayConfig routerConfig;
    private final HealthBoxJwtConfig jwtConfig;
    private final HealthBoxSecurityConfig securityConfig;
    private final HealthBoxUserModifyService modifyService;
    @Override
    public void run(String... args) throws Exception {
        log.info("displaying configurations");
        log.info(routerConfig.toString());
        log.info(jwtConfig.toString());
        log.info(securityConfig.toString());
        log.info("displayed configurations");
//        HealthBoxUserVO organ = insert(randomUser(HealthBoxUserRole.ORGAN_ADMIN), "organ");
//        log.info(organ.toString());
    }

    private HealthBoxUserVO randomUser(HealthBoxUserRole role) {
        return HealthBoxUserVO.builder()
                .id(null)
                .userPhone("organ")
                .name("organ_admin")
                .idNumber("127319824612")
                .locked(false)
                .role(role)
                .build();
    }
    private HealthBoxUserVO insert(HealthBoxUserVO vo, String password) {
        return modifyService.register(vo, password);
    }
}
